import { globalTool } from './BQGIS-globalVar'

export function initBGGIS_measure(viewer = window.viewer) {
    if (!globalTool.measure) {
        globalTool.measure = new mars3d.thing.Measure({
            label: {
                color: "#ffffff",
                font_family: "楷体",
                font_size: 20,
                background: false
            }
        })
        viewer.addThing(globalTool.measure)
    }
}



export function onlyPickModelPosition(boole, viewer = window.viewer) {
    // 控制鼠标只取模型上的点，忽略地形上的点的拾取
    viewer.onlyPickModelPosition = boole
}

export function removeAll() {
    globalTool.measure.clear()
    if (viewer.scene.requestRenderMode) {
        viewer.scene.requestRender();
    }
}

// 空间距离
export function measureLength() {
    globalTool.measure.distance({
        showAddText: true,
        label: {
            // 自定义显示label的graphic类型
            type: "div",
            updateText: function (text, graphic) {
                // updateText是必须，用于动态更新 text
                graphic.html = `<div class="marsGreenGradientPnl" >${text}</div>`
            },
            // 下面是graphic对应类型本身的参数
            html: `<div class="marsGreenGradientPnl" ></div>`,
            horizontalOrigin: Cesium.HorizontalOrigin.CENTER,
            verticalOrigin: Cesium.VerticalOrigin.BOTTOM
        }
    })
}
// 贴地距离
export function measureSurfaceLength() {
    globalTool.measure.distanceSurface({
        showAddText: true
        // unit: 'm', //支持传入指定计量单位
        // style: {
        //   color: '#ffff00',
        //   width: 3,
        //   clampToGround: true //是否贴地
        // }
    })
}
// 水平面积
export function measureArea() {
    globalTool.measure.area({
        style: {
            color: '#00fff2',
            //   opacity: 0.4,
            outline: true,
            outlineColor: '#fafa5a',
            outlineWidth: 1,
            clampToGround: false, //贴地
        }
    })
}

// 贴地面积
export function measureSurfaceeArea() {
    globalTool.measure.areaSurface({
        style: {
            color: "#ffff00"
        },
        splitNum: 10 // step插值分割的个数
    })
}

// 高度差
export function measureHeight() {
    globalTool.measure.height()
}

// 三角测量
export function measureTriangleHeight() {
    globalTool.measure.heightTriangle()
}

// 方位角
export function measureAngle() {
    globalTool.measure.angle()
}

// 坐标测量
export function measurePoint() {
    globalTool.measure.point()
}